package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Employeeinfo;
import cn.wolfcode.crm.qo.EmployeeInfoQueryObject;
import cn.wolfcode.crm.qo.PageResult;
import cn.wolfcode.crm.service.IEmployeeinfoService;
import cn.wolfcode.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@RequestMapping("employeeInfo")
@Controller
public class EmployeeinfoController {
    @Autowired
    private IEmployeeinfoService employeeinfoService;

    @RequestMapping("view")
    public String list(){
        return "employeeinfo/employeeInfo";
    }

    //异步加载数据
    @RequestMapping("query")
    @ResponseBody
    public Object list(@ModelAttribute("qo") EmployeeInfoQueryObject qo, Model model) {
        //将数据转换成json格式
        PageResult result = employeeinfoService.queryForList(qo);

        return result;
    }


    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Employeeinfo entity){
        JSONResult result = new JSONResult();
        try {
            employeeinfoService.saveOrUpdate(entity);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

}

